<?php
	$monthNames = array(
		1 => 'Január', 2 => 'Február', 3 => 'Marec', 4 => 'Apríl', 5 => 'Máj', 6 => 'Jún',
		7 => 'Júl', 8 => 'August', 9 => 'September', 10 => 'Október', 11 => 'November', 12 => 'December'
	);
?>
<?php
$this->pageTitle = 'Zoznam depozitov';
?>

<div class="listing">
	<h3>Zoznam depozitov</h3>
	<div class="top_links">
		<?php
			$totalTitle = 'SPOLU';
			if ($actualType == 'total') {
				echo '<strong>' . $totalTitle . '</strong>';
			} else {
				echo $this->Html->link($totalTitle, array('controller' => 'commission', 'action' => 'index'));
			}
		?>
		<span> | </span>
		<?php
			$companyTitle = 'Firma';
			if ($actualType == 'company') {
				echo '<strong>' . $companyTitle . '</strong>';
			} else {
				echo $this->Html->link($companyTitle, array('controller' => 'commission', 'action' => 'index', 'company'));
			}
		?>
		<span> | </span>
		<?php
			$netTitle = 'Siete';
			if ($actualType == 'net') {
				echo '<strong>' . $netTitle . '</strong>';
			} else {
				echo $this->Html->link($netTitle, array('controller' => 'commission', 'action' => 'index', 'net'));
			}
		?>
		<span> | </span>
		<?php
			$brokerTitle = 'Makléri';
			if ($actualType == 'broker') {
				echo '<strong>' . $brokerTitle . '</strong>';
			} else {
				echo $this->Html->link($brokerTitle, array('controller' => 'commission', 'action' => 'index', 'broker'));
			}
		?>
		<span> | </span>
		<?php
			$companiesTitle = 'Finančné spoločnosti';
			if ($actualType == 'companies') {
				echo '<strong>' . $companiesTitle . '</strong>';
			} else {
				echo $this->Html->link($companiesTitle, array('controller' => 'commission', 'action' => 'index', 'companies'));
			}
		?>
		<div class="clear"></div>
		<?php foreach ($years as $year) {
				if ($year == $actualYear) {
					echo '<strong>' . $year . '</strong>';
				} else {
					echo $this->Html->link($year, array('controller' => 'commission', 'action' => 'index', $actualType, $year));
				}
				if ($year != min($years)) {
					echo '<span> | </span>';
				}
			}
		?>
		<?php if ($actualYear): ?>
		<div class="clear"></div>
		<?php
			foreach ($monthNames as $index => $month) {
				$shortMonthName = mb_substr($month, 0, 3);
				if ($index == $actualMonth) {
					echo '<strong>' . $shortMonthName . '</strong>';
				} elseif ($actualYear) {
					echo $this->Html->link($shortMonthName, array('controller' => 'commission', 'action' => 'index', $actualType, $actualYear, $index));
				} else {
					echo $shortMonthName;
				}
				if ($index != 12) {
					echo '<span> | </span>';
				}
			}
		?>
		<?php endif; ?>
		<div class="clear"></div>
		<?php echo '<p style="font-size: 56px;">' . number_format($totalCommission, 2, ',', ' ') . ' &euro;</p>'; ?>
	</div>
	<table class="list">
		<thead>
			<tr>
				<th class="identifier"><?php echo $this->Paginator->sort('id', 'ID'); ?></th>
				<th class="col100"><?php echo $this->Paginator->sort('fk_transfer_id', 'Obrat'); ?></th>
				<th class="col100"><?php echo $this->Paginator->sort('fk_person_id', 'Osoba'); ?></th>
				<th class="col100"><?php echo $this->Paginator->sort('fk_person_type_id', 'Typ osoby'); ?></th>
				<th class="col20"><?php echo $this->Paginator->sort('percentage', '%'); ?></th>
				<th class="col50"><?php echo $this->Paginator->sort('value', 'Hodnota (€)'); ?></th>
				<?php if (isset($userPermissions['commission']['view']) || isset($userPermissions['commission']['edit']) || isset($userPermissions['commission']['delete'])): ?>
				<th class="action"><?php echo 'Akcie'; ?></th>
				<?php endif; ?>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ($commissions as $commission):
			?>
			<tr>
				<td class="number">
					<?php echo $commission['Commission']['id']; ?>
				</td>
				<td>
					<?php echo $this->Html->link('Detail', array('controller' => 'transfer', 'action' => 'view', $commission['Transfer']['id'])); ?>
				</td>
				<td>
					<?php echo $this->Html->link(htmlspecialchars($commission['Person']['full_name']), array('controller' => 'person', 'action' => 'view', $commission['Person']['id'])); ?>
				</td>
				<td>
					<?php echo $this->Html->link(htmlspecialchars($commission['PersonType']['title']), array('controller' => 'person_type', 'action' => 'view', $commission['PersonType']['id'])); ?>
				</td>
				<td class="number">
					<?php echo $commission['Commission']['percentage']; ?>
				</td>
				<td class="number">
					<?php echo number_format($commission['Commission']['value'], 2, ',', ' '); ?>
				</td>
				<?php if (isset($userPermissions['commission']['view']) || isset($userPermissions['commission']['edit']) || isset($userPermissions['commission']['delete'])): ?>
				<td>
					<?php
						if (isset($userPermissions['commission']['view'])) {
							echo $this->Html->link(__('View', true), array('action' => 'view', $commission['Commission']['id']), array('class' => 'show'));
						}
					?>
					<?php
						if (isset($userPermissions['commission']['edit'])) {
							echo $this->Html->link(__('Uprav', true), array('action' => 'edit', $commission['Commission']['id']), array('class' => 'edit'));
						}
					?>
					<?php
						if (isset($userPermissions['commission']['delete'])) {
							echo $this->Html->link(__('Delete', true), array('action' => 'delete', $commission['Commission']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
						}
					?>
				</td>
				<?php endif; ?>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

	<?php if ($this->Paginator->hasPage(2)): ?>
		<div class="pager">
			<?php echo $this->Paginator->prev('<< '.__('predchádzajúca', true), array(), null, array('class'=>'disabled')); ?>
			<?php echo $this->Paginator->numbers(); ?>
			<?php echo $this->Paginator->next(__('ďalšia', true).' >>', array(), null, array('class' => 'disabled')); ?>
		</div>
	<?php endif; ?>
</div>